--图标刷新动画
class.button_animation = extends(class.panel)
{
    new = function (parent)
        local panel = class.button_animation:builder 
        {
            parent = parent, 
            x = 0,
            y = 0,
            w = 32,
            h = 32,
            normal_image = '',
        }
        return panel 
    end,

    play_animation = function (self, x, y, w, h, path, interval, max_tick)
        if self.timer then 
            self.timer:remove()
        end 

        self:set_control_size(w, h)
        self:set_position(x, y)
        
        self:show()
        self:set_normal_image('')

        local i = 0
        self.timer = game.tick.timer(interval * 1000, max_tick, function ()
            i = i + 1 
            local path = path .. '\\' .. i .. '.blp'

            self:set_normal_image(path)
            if i == max_tick then 
                self:hide()
            end 
        end)
    end,

    stop_animation = function (self)
        if self.timer then 
            self.timer:remove()
            self.timer = nil 
        end 
        self:set_normal_image('')
        self:hide()
    end,

    loop_animation = function (self, x, y, w, h, path, interval, max_tick)
        if self.timer then 
            self.timer:remove()
        end 

        self:set_control_size(w, h)
        self:set_position(x, y)
        
        self:show()
        self:set_normal_image('')

        local i = 0
        local flag = 1
        -- self.timer = game.tick.loop(interval * 1000, function ()
        --     i = i + flag 
        --     local path = path .. '\\' .. i .. '.blp'

        --     self:set_normal_image(path)
        --     if i == max_tick then 
        --         flag = -1
        --     elseif i == 1 then
        --         flag = 1
        --     end

        -- end)
    end
}

